package com.alen.sun.dao;

import com.alen.sun.bean.Captcha;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface CaptchaMapper {

    /**
     * 添加手机号和验证码记录
     * @param captcha
     */
    @Insert("INSERT INTO captcha (phone_num, captcha) VALUES (#{phoneNum}, #{captcha})")
    void addCaptcha(Captcha captcha);


    /**
     * 查找手机号是否存在
     * @param phoneNum
     * @return
     */
    @Select("SELECT * FROM captcha WHERE phone_num = #{phoneNum}")
    Boolean selectPhoneNum(String phoneNum);

    /**
     * 修改已存在的手机号对应的验证码
     * @param captcha
     */
    @Update("UPDATE captcha SET captcha = #{captcha} WHERE phone_num = #{phoneNum}")
    void updateCaptcha(Captcha captcha);

    /**
     * 注册账号用于比对验证码和手机号
     * @param phoneNum
     * @param captcha
     * @return
     */
    @Select("SELECT count(*) FROM captcha WHERE phone_num = #{phoneNum} and captcha = #{captcha}")
    Boolean selectByPhoneNumAndCaptcha(String phoneNum,String captcha);
}
